/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * QLNhapKho.java
 *
 * Created on Nov 11, 2012, 11:22:39 AM
 */
package doan;

import Dao.CTPhieuNhapKhoDao;
import Dao.KhaNangCungUngDao;
import Dao.NhaCungCapDao;
import Dao.NhanVienDao;
import Dao.PhieuNhapKhoDao;
import Pojo.CTPhieuNhapKhoPojo;
import Pojo.KhaNangCungUngPojo;
import Pojo.NhaCungCapPojo;
import Pojo.NhanVienPojo;
import Pojo.PhieuNhapKhoPojo;
import Pojo.SanPhamPojo;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author LETHOM
 */
public class QLNhapKho extends javax.swing.JFrame {

    private DefaultComboBoxModel cbmodel;
    private DefaultComboBoxModel cbmodel1;
    private DefaultComboBoxModel cbmodel2;
    private DefaultComboBoxModel cbmodelsp;
    private int mapn;
            
    private DefaultTableModel tbmodel;
    /** Creates new form QLNhapKho */
    public QLNhapKho() {
        initComponents();
        this.cbmodel= new DefaultComboBoxModel();
        this.cmbnhacungcap.setModel(cbmodel);        
        loadNCC();
        
        this.cbmodel1=new DefaultComboBoxModel();
        this.cmbnhanvien.setModel(cbmodel1);        
loadNhanVien();

//this.tbmodel=new DefaultTableModel();
//this.tbdsctphieunhapkho.setModel(tbmodel);
loaddsphieunhapkho();
this.cbmodel2=new DefaultComboBoxModel();
this.cmbnhacungcap1.setModel(cbmodel2);

this.cbmodelsp=new DefaultComboBoxModel();
this.cmbsanpham.setModel(cbmodelsp);



//Lay gio he thong
Date todayD=new Date(System.currentTimeMillis()); 

//Khai bao dinh dang ngay thang
SimpleDateFormat dayFormat= new SimpleDateFormat("dd/MM/yyyy"); 

//parse ngay thang sang dinh dang va chuyen thanh string.
String todayS=dayFormat.format(todayD.getTime());  
lbngaynhap.setText(todayS);
    
    }
    public void loadNhanVien()
    {          
        ArrayList<NhanVienPojo> ds= NhanVienDao.DSNhanVien();
        //for(PhongBanPojo pb : ds)
        for(int i=0;i<ds.size();i++)
        {
            this.cbmodel1.addElement(ds.get(i));
        }
    }
    public void loaddsphieunhapkho()
    {
        ArrayList<PhieuNhapKhoPojo>ds=PhieuNhapKhoDao.DSPhieuNhapKho();
        String[]columns=new String[]{"STT","Mã phiếu nhập","Ngày nhập","Mã nhà cung cấp","Mã nhân viên phụ trách"};
      DefaultTableModel tbmodel3 =new DefaultTableModel(null,columns);
        for(PhieuNhapKhoPojo pnk:ds)
        {
            Integer i=1;
           
            Object[]items;
            items = new Object[]
     {    i,
         pnk.getMaPhieuNhap(),
          pnk.getNgayNhap(),                   
           pnk.getMaNCC(),
          pnk.getMaNV()
      };           
            tbmodel3.addRow(items);
            
             
        }
        tbdsphieunhapkho.setModel(tbmodel3);
    }
public void loadsanpham(int mancc)
{
ArrayList<KhaNangCungUngPojo>ds=KhaNangCungUngDao.DSSanPhamTheoMaNCC(mancc);
for(int i=0;i<ds.size();i++)
{
        this.cbmodelsp.addElement(ds.get(i));
}
}
    public void loadNCC()
    {
        
        ArrayList<NhaCungCapPojo> ds=NhaCungCapDao.DSNhaCungCap();
        for(int i=0;i<ds.size();i++)
        {
            this.cbmodel.addElement(ds.get(i));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbdsctphieunhapkho = new javax.swing.JTable();
        jButton4 = new javax.swing.JButton();
        btndong = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        cmbnhacungcap = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        btnlapphieu = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        cmbnhanvien = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        lbngaynhap = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        cmbnhacungcap1 = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        txtsoluong = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cmbsanpham = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtgianhap = new javax.swing.JTextField();
        btnthemsp = new javax.swing.JButton();
        btnsua = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tbdsphieunhapkho = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Quản lý nhậpkho");
        setMinimumSize(new java.awt.Dimension(1000, 1000));

        jLabel2.setText("Danh Sách Phiếu Nhập Kho");

        tbdsctphieunhapkho.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "STT", "Mã chi tiết phiếu nhập", "Mã phiếu nhập", "Mã sản phẩm", "Số lượng", "Giá nhập"
            }
        ));
        tbdsctphieunhapkho.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbdsctphieunhapkhoMouseClicked(evt);
            }
        });
        tbdsctphieunhapkho.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbdsctphieunhapkhoKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(tbdsctphieunhapkho);

        jButton4.setText("Xóa");
        jButton4.setName("btnXoa"); // NOI18N

        btndong.setText("Đóng");
        btndong.setName("btnThoat"); // NOI18N

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));
        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel5.setText("Nhà cung ứng");

        btnlapphieu.setText("Lập phiếu nhậpkho");
        btnlapphieu.setName("btnThempn"); // NOI18N
        btnlapphieu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnlapphieuActionPerformed(evt);
            }
        });

        jButton3.setText("Sửa");
        jButton3.setName("btnSua"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 24));
        jLabel4.setText("Lập phiếu nhập kho");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(cmbnhacungcap, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(95, 95, 95)
                .addComponent(jLabel4))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(580, 580, 580)
                .addComponent(jButton3))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(89, 89, 89)
                .addComponent(btnlapphieu))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel4)
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(cmbnhacungcap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnlapphieu)
                .addGap(181, 181, 181)
                .addComponent(jButton3))
        );

        cmbnhanvien.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nguyễn Văn A" }));
        cmbnhanvien.setMaximumSize(new java.awt.Dimension(30, 30));
        cmbnhanvien.setMinimumSize(new java.awt.Dimension(30, 30));
        cmbnhanvien.setName("cbxNhanVienphutrach"); // NOI18N
        cmbnhanvien.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbnhanvienActionPerformed(evt);
            }
        });

        jLabel3.setText("Nhân viên phụ Trách ");

        lbngaynhap.setText("01/01/2012");

        jLabel11.setText("Ngày:");

        jPanel2.setBackground(new java.awt.Color(204, 204, 204));
        jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel8.setText("Nhà cung ứng");

        jButton5.setText("Sửa");
        jButton5.setName("btnSua"); // NOI18N

        jLabel9.setText("Giá nhập:");

        txtsoluong.setName("txtNgayLap"); // NOI18N
        txtsoluong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtsoluongActionPerformed(evt);
            }
        });

        jLabel10.setText("Số lượng:");

        cmbsanpham.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbsanphamActionPerformed(evt);
            }
        });

        jLabel15.setText("Sản phẩm:");

        jLabel12.setFont(new java.awt.Font("Times New Roman", 0, 24));
        jLabel12.setText("Nhập sản phẩm");

        txtgianhap.setName("txtNgayLap"); // NOI18N
        txtgianhap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtgianhapActionPerformed(evt);
            }
        });

        btnthemsp.setText("Thêm");
        btnthemsp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnthemspActionPerformed(evt);
            }
        });

        btnsua.setText("Sửa");
        btnsua.setName("btnChiTietpn"); // NOI18N
        btnsua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsuaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addComponent(jLabel12))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(580, 580, 580)
                .addComponent(jButton5))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                    .addGap(109, 109, 109)
                    .addComponent(btnthemsp)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnsua))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                    .addGap(37, 37, 37)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel8)
                        .addComponent(jLabel15)
                        .addComponent(jLabel10)
                        .addComponent(jLabel9))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(cmbsanpham, 0, 150, Short.MAX_VALUE)
                        .addComponent(txtsoluong)
                        .addComponent(cmbnhacungcap1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtgianhap))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel12)
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(cmbnhacungcap1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(222, 222, 222)
                        .addComponent(jButton5))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbsanpham, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addGap(20, 20, 20)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(txtsoluong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jLabel9))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(txtgianhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnthemsp)
                            .addComponent(btnsua)))))
        );

        tbdsphieunhapkho.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "STT", "Mã phiếu nhập", "Mã nhân viên", "Ngày nhập"
            }
        ));
        tbdsphieunhapkho.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbdsphieunhapkhoMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tbdsphieunhapkho);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(610, 610, 610)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(cmbnhanvien, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel2)
                        .addGap(461, 461, 461)
                        .addComponent(jLabel11)
                        .addGap(91, 91, 91)
                        .addComponent(lbngaynhap))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                            .addComponent(jScrollPane3))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(293, 293, 293)
                        .addComponent(jButton4)
                        .addGap(68, 68, 68)
                        .addComponent(btndong, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(69, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(cmbnhanvien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(lbngaynhap))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton4)
                    .addComponent(btndong))
                .addGap(241, 241, 241))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbnhanvienActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbnhanvienActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_cmbnhanvienActionPerformed

    private void btnlapphieuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnlapphieuActionPerformed
        // TODO add your handling code here:
         PhieuNhapKhoPojo nv=new PhieuNhapKhoPojo();       
                 //nv.setManv(txtma.getText())  ;              
                nv.setNgayNhap(lbngaynhap.getText());             
               //int phong=rs.getInt("PHG");
              Integer ncc=((NhaCungCapPojo)cmbnhacungcap.getSelectedItem()).getMaNCC();
                nv.setMaNCC(ncc); 
                Integer manv=((NhanVienPojo)cmbnhanvien.getSelectedItem()).getMaNV();
                nv.setMaNV(manv); 
               //Date ngaysinh = Date.parse(txtngaysinh.getText());
              // nv.setNgaysinh(ngaysinh);
//               nv.setPhai(txtphai.getText());               
//                nv.setLuong(Double.parseDouble(txtluong.getText()));
//                 nv.setMaNQL(((NhanVienPojo)cmbmaql.getSelectedItem()).getMaNQL());  
                boolean n= false;
                n = PhieuNhapKhoDao.ThemPhieuNhapKho(nv);
            if(n==true)
            {
              JOptionPane.showMessageDialog(this,"Them thanh cong","Thong bao",JOptionPane.INFORMATION_MESSAGE); 
              loaddsphieunhapkho();
                        
             }
            else
            {
                 JOptionPane.showMessageDialog(this,"Them khong thanh cong","Thong bao",JOptionPane.INFORMATION_MESSAGE);       
                        
             }
    }//GEN-LAST:event_btnlapphieuActionPerformed

    private void tbdsctphieunhapkhoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbdsctphieunhapkhoKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_tbdsctphieunhapkhoKeyPressed

    private void tbdsctphieunhapkhoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbdsctphieunhapkhoMouseClicked
        // TODO add your handling code here:
        int dong=this.tbdsphieunhapkho.getSelectedRow();
      String soluong=this.tbdsctphieunhapkho.getValueAt(dong, 4).toString();
        Double gianhap=Double.parseDouble(this.tbdsctphieunhapkho.getValueAt(dong, 5).toString());
        this.txtgianhap.setText(gianhap.toString());
        this.txtsoluong.setText(soluong);
//        loadncctheods(mancc);
//        loadctphieunhap(maphieunhap);
//        mapn=maphieunhap;        
//        loadsanpham(mancc);
        
    }//GEN-LAST:event_tbdsctphieunhapkhoMouseClicked

    private void txtsoluongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtsoluongActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtsoluongActionPerformed

    public void loadncctheods(int mancc)
    {
       // this.cmbnhacungcap1.enable();
        ArrayList<NhaCungCapPojo> ds=NhaCungCapDao.DSNCCTheoMa(mancc);
        for(int i=0;i<ds.size();i++)
        {
            this.cbmodel2.addElement(ds.get(i));
        } 
        //this.cmbnhacungcap1.disable();
    }
    public void loadctphieunhap(int maphieunhap)
    {
        ArrayList<CTPhieuNhapKhoPojo>ds=CTPhieuNhapKhoDao.DSCTPhieuNhapKhoTheoMa(maphieunhap);
        String[]colums=new String[]{"STT","Mã chi tiết phiếu nhập","Mã phiếu nhập","Mã sản phẩm","Số lượng","Giá nhập"};
        DefaultTableModel tbmodel3 =new DefaultTableModel(null,colums);
        for(CTPhieuNhapKhoPojo pnk:ds)
        {
            Integer i=1;
           
            Object[]items;
            items = new Object[]
     {    i,
     pnk.getMaCTPNK(),
         pnk.getMaPhieuNhap(),
          pnk.getMaSP(),                   
           pnk.getSoLuong(),
          pnk.getGiaNhap()
      };           
            tbmodel3.addRow(items);            
             
        }
        tbdsctphieunhapkho.setModel(tbmodel3);
                
    }
    
    private void tbdsphieunhapkhoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbdsphieunhapkhoMouseClicked
        // TODO add your handling code here:
        int dong=this.tbdsphieunhapkho.getSelectedRow();
      int maphieunhap=Integer.parseInt(this.tbdsphieunhapkho.getValueAt(dong, 1).toString());
        int mancc=Integer.parseInt(this.tbdsphieunhapkho.getValueAt(dong, 3).toString());
        loadncctheods(mancc);
        loadctphieunhap(maphieunhap);
        mapn=maphieunhap;        
        loadsanpham(mancc);
        
       
//        this.txtma3.setText(mahocsinh);
//        this.txtten3.setText(tenhocsinh);
        
    }//GEN-LAST:event_tbdsphieunhapkhoMouseClicked

    private void cmbsanphamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbsanphamActionPerformed
        // TODO add your handling code here:
//        SanPhamPojo sp=(SanPhamPojo)this.cmbsanpham.getSelectedItem();
//        this.lbgianhap.setText(sp.getGiaBan());
    }//GEN-LAST:event_cmbsanphamActionPerformed

    private void txtgianhapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtgianhapActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtgianhapActionPerformed

    private void btnthemspActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnthemspActionPerformed
        // TODO add your handling code here:
        CTPhieuNhapKhoPojo ctpnk=new CTPhieuNhapKhoPojo();
        ctpnk.setGiaNhap(Double.parseDouble(txtgianhap.getText()));
        ctpnk.setSoLuong(Integer.parseInt(txtsoluong.getText()));
        ctpnk.setMaPhieuNhap(mapn);
         Integer masp=((KhaNangCungUngPojo)cmbsanpham.getSelectedItem()).getMaSP();
        ctpnk.setMaSP(masp);
           boolean n= false;
                n = CTPhieuNhapKhoDao.ThemCTPhieuNhapKho(ctpnk);
            if(n==true)
            {
              JOptionPane.showMessageDialog(this,"Them thanh cong","Thong bao",JOptionPane.INFORMATION_MESSAGE); 
              loadctphieunhap(mapn);
                        
             }
            else
            {
                 JOptionPane.showMessageDialog(this,"Them khong thanh cong","Thong bao",JOptionPane.INFORMATION_MESSAGE);       
                        
             }
      
    }//GEN-LAST:event_btnthemspActionPerformed

    private void btnsuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsuaActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_btnsuaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new QLNhapKho().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btndong;
    private javax.swing.JButton btnlapphieu;
    private javax.swing.JButton btnsua;
    private javax.swing.JButton btnthemsp;
    private javax.swing.JComboBox cmbnhacungcap;
    private javax.swing.JComboBox cmbnhacungcap1;
    private javax.swing.JComboBox cmbnhanvien;
    private javax.swing.JComboBox cmbsanpham;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lbngaynhap;
    private javax.swing.JTable tbdsctphieunhapkho;
    private javax.swing.JTable tbdsphieunhapkho;
    private javax.swing.JTextField txtgianhap;
    private javax.swing.JTextField txtsoluong;
    // End of variables declaration//GEN-END:variables
}
